import {defineStore} from "pinia";
import {getUserInfo} from "@/api/user/UserApi";
import {getToken} from "@/utils/TokenUtil";
import sysConfig from "@/config/index"
/**
 *  文档
 *  https://pinia.web3doc.top/introduction.html#%E5%9F%BA%E6%9C%AC%E7%A4%BA%E4%BE%8B
 *
 * */
export default defineStore("user",{
    state:()=>{

        const userId=0
        const name=""
        const account=""
        const avatar=""
        return{
            userId,
            name,
            account,
            avatar

        }
    },
    actions:{

       clear(){
           this.$reset()
           // this.userId=0
           // this.account=""
           // this.name=""
           // this.avatar=""
       },
        getUser(){
           if(getToken()){
               getUserInfo().then(resp=>{
                   // @ts-ignore
                   if(resp.code === 200){
                       this.userId=resp.data.id
                       this.account=resp.data.account
                       this.name=resp.data.name
                       this.avatar=resp.data.avatar
                   }
               })
           }

        }
    },

    persist:{
        enabled:true
    }
})